//***************************************//
//**       mMath 11-12-2012            **//
//**    Riku Maikola rpm@ac-mapa.org   **//
// **************************************//
#include "mArea.h"
//Class Biggest
mArea::mArea()
{
    L=mPoint(NAN,NAN,NAN);
    H=mPoint(NAN,NAN,NAN);
}
//test value if bigger
void mArea::test(mPoint Axis)
{
    if(!isnan(Axis.x))
    {
        if(isnan(L.x))L.x=Axis.x;
        if(isnan(H.x))H.x=Axis.x;
        if(L.x>Axis.x)L.x=Axis.x;
        if(H.x<Axis.x)H.x=Axis.x;
    }
    if(!isnan(Axis.y))
    {
        if(isnan(L.y))L.y=Axis.y;
        if(isnan(H.y))H.y=Axis.y;
        if(L.y>Axis.y)L.y=Axis.y;
        if(H.y<Axis.y)H.y=Axis.y;
    }
    if(!isnan(Axis.z))
    {
        if(isnan(L.z))L.z=Axis.z;
        if(isnan(H.z))H.z=Axis.z;
        if(L.z>Axis.z)L.z=Axis.z;
        if(H.z<Axis.z)H.z=Axis.z;
    }
}

void mArea::test(double xAxis,double yAxis,double zAxis)
{
    if(!isnan(xAxis))
    {
        if(isnan(L.x))L.x=xAxis;
        if(isnan(H.x))H.x=xAxis;
        if(L.x>xAxis)L.x=xAxis;
        if(H.x<xAxis)H.x=xAxis;
    }
    if(!isnan(yAxis))
    {
        if(isnan(L.y))L.y=yAxis;
        if(isnan(H.y))H.y=yAxis;
        if(L.y>yAxis)L.y=yAxis;
        if(H.y<yAxis)H.y=yAxis;
    }
    if(!isnan(zAxis))
    {
        if(isnan(L.z))L.z=zAxis;
        if(isnan(H.z))H.z=zAxis;
        if(L.z>xAxis)L.z=zAxis;
        if(H.z<xAxis)H.z=zAxis;
    }
}
bool mArea::IsInX(double x)
{
    if(x>H.x)return false;
    if(x<L.x)return false;
    return true;
}
bool mArea::IsInY(double y)
{
    if(y>H.y)return false;
    if(y<L.y)return false;
    return true;
}
bool mArea::IsInZ(double z)
{
    if(z>H.z)return false;
    if(z<L.z)return false;
    return true;
}
bool mArea::IsInArea(double x,double y,double z)
{
    if(!IsInX(x))return false;
    if(!IsInY(y))return false;
    if(!IsInZ(z))return false;
    return true;
}


bool mArea::IsAreaInSide(mArea T)
{
    if( T.H.y > H.y  && T.L.y < L.y && T.H.x > H.x  && T.L.x < L.x )
        return true;

    return false;
};


void mArea::ClearArea()
{
    L=mPoint(NAN,NAN,NAN);
    H=mPoint(NAN,NAN,NAN);
};
